package net.moao.netutils_library.http;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;
import java.util.Map;

/**
 * HttpResponse
 *
 * @author Moao.Net
 * @DATE 2017/11/22
 */
public class HttpResponse {
    Integer code;
    Map<String, List<String>> headers;
    StringBuffer body;

    public HttpResponse(Integer code, Map<String, List<String>> headers, StringBuffer body) {
        this.code = code;
        this.headers = headers;
        this.body = body;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Map<String, List<String>> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, List<String>> headers) {
        this.headers = headers;
    }

    public StringBuffer getBody() {
        return body;
    }

    public void setBody(StringBuffer body) {
        this.body = body;
    }

    public String toJsonString() throws JSONException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", this.code);
        jsonObject.put("headers", this.headers);
        jsonObject.put("body", this.body.toString());
        return jsonObject.toString();
    }
}
